package ua.exchangeratesukraine.ui.fragment;

import ua.exchangeratesukraine.R;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

public class FragmentMenu extends Fragment implements OnClickListener {

	private String				LOG_TAG			= getClass().getSimpleName();
	private Button				btnNBU, btnBanks, btnAbout;
	private FragmentNbu			fragmentNbu		= null;
	private FragmentBanks		fragmentBanks	= null;
	private FragmentAbout		fragmentAbout	= null;
	// Listener for sending a position in activity
	private SetActionListener	SetDataListener;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

		View view = inflater.inflate(R.layout.fragment_menu, null);

		btnNBU = (Button) view.findViewById(R.id.btnNBU);
		btnBanks = (Button) view.findViewById(R.id.btnBanks);
		btnAbout = (Button) view.findViewById(R.id.btnAbout);
		btnNBU.setOnClickListener(this);
		btnBanks.setOnClickListener(this);
		btnAbout.setOnClickListener(this);
		fragmentNbu = new FragmentNbu();
		fragmentBanks = new FragmentBanks();
		fragmentAbout = new FragmentAbout();
		return view;
	}

	@Override
	public void onClick(View v) {

		FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();

		switch (v.getId()) {
			case R.id.btnNBU:
				ft.replace(R.id.fragmentLayout, fragmentNbu);

				break;
			case R.id.btnBanks:
				ft.replace(R.id.fragmentLayout, fragmentBanks);

				break;
			case R.id.btnAbout:
				ft.replace(R.id.fragmentLayout, fragmentAbout);

				break;
			default:
				break;
		}
		SetDataListener.setAction();
		ft.addToBackStack(null);
		ft.commit();
	}

	@Override
	public void onAttach(Activity activity) {

		super.onAttach(activity);
		try {
			SetDataListener = (SetActionListener) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(activity.toString() + " must implement SetDataListener");
		}
	}

}